﻿namespace Oddo.Concept.Crm.Common.Localization
{
    using System;
    using System.Globalization;
    using System.Resources;

    /// <summary>
    /// Service de traduction par defaut
    /// </summary>
    public class DefaultTranslationService : ITranslationServices
    {
        private readonly ResourceManager _manager;

        public DefaultTranslationService(ResourceManager resourceManager)
        {
            if (resourceManager == null) throw new ArgumentNullException("resourceManager");
            _manager = resourceManager;
        }

        public virtual string GetCurrentCultureText(string key)
        {
            if (string.IsNullOrWhiteSpace(key)) throw new ArgumentNullException("key");
            return _manager.GetString(key);
        }

        public virtual string GetCurrentCultureText(string key, string defaultValue)
        {
            if (string.IsNullOrWhiteSpace(key)) throw new ArgumentNullException("key");
            var value = _manager.GetString(key);
            return String.IsNullOrWhiteSpace(value) ? defaultValue : value;
        }

        public virtual string GetCultureText(string key, CultureInfo culture)
        {
            if (string.IsNullOrWhiteSpace(key)) throw new ArgumentNullException("key");
            if (culture == null) throw new ArgumentNullException("culture");
            return _manager.GetString(key, culture);
        }

        public virtual string GetCultureText(string key, CultureInfo culture, string defaultValue)
        {
            if (string.IsNullOrWhiteSpace(key)) throw new ArgumentNullException("key");
            if (culture == null) throw new ArgumentNullException("culture");
            var value = _manager.GetString(key, culture);
            return string.IsNullOrWhiteSpace(value) ? defaultValue : value;
        }
    }
}